<template>
  <div>
    <div class="pltxt" v-if="setName!=undefined">{{setName}} <span v-if="setUntil!=undefined">({{setUntil}})</span></div>
    <van-field v-model="lang_parent" clickable readonly @click="showPicker = true">
        <template #button>
          <van-button size="small" round @click="setLang($event)" class="setbtn">{{$t('Save')}}</van-button>
        </template>
    </van-field>
    <van-popup v-model="showPicker" round position="bottom">
      <van-picker show-toolbar 
        :columns="columns" 
        @cancel="showPicker = false" 
        @confirm="onConfirm" 
        :confirm-button-text="$t('OK')"
        :cancel-button-text="$t('Cancel')"
      />
    </van-popup>
  </div>
</template>

<script>

export default {
  props:['setName','setUntil','columns','setValue','reg','pre'],
  data(){
    return {
      activeNames:[],
      showPicker:false,
      lang_parent:this.setValue
    }
  },
  watch:{
    setValue(newVal){
      this.lang_parent=newVal;
    }
  },
  methods: {
    onConfirm(value){
      this.showPicker=false;
      this.lang_parent=value;
      this.$emit('returnCode',value);
    },
    async setLang(e){
      e.stopPropagation();
      //处理数据
      let params={
        'optType':'setReg',
        'num':1,
        'sn':localStorage.getItem('wifiSN'),
        'tokenId':localStorage.getItem('tokenId'),
        'Data':JSON.stringify([{'reg':this.reg,val:this.comm.mulFunction(this.lang_parent,this.pre)}])
      };
      this.comm.loadingShow();
      let data = await this.SETAPI.setInvMachinePT(localStorage.getItem('domain'), params);
      if (data.success) {
        this.comm.toastSuccess();
        this.$emit('getFormData',this.lang_parent);
      }else {
        this.comm.toastFail();
      }
    }
  }
}
</script>

<style scoped lang="less">

</style>